package com.fenghongzhang.gao4;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;

import com.fenghongzhang.gao4.fragment.OneFragment;
import com.fenghongzhang.gao4.fragment.TwoFragment;
import com.flyco.tablayout.SlidingTabLayout;
import com.flyco.tablayout.listener.OnTabSelectListener;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class VPandTABActivity extends AppCompatActivity {
    private SlidingTabLayout slidingTabLayout;
    private ViewPager vp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_v_pand_t_a_b);


        slidingTabLayout = (SlidingTabLayout) findViewById(R.id.sliding_tab_layout);

        vp = (ViewPager) findViewById(R.id.vp);

        List<Fragment> list = new ArrayList<>();
        list.add(new OneFragment());
        list.add(new TwoFragment());

        vp.setAdapter(new MyAdapter(getSupportFragmentManager(),list));
        List<String> strings = new ArrayList<>();
        strings.add("关注");
        strings.add("喜欢");

//        String[] s = new String[2];
//        List<String> strings1 = Arrays.asList(s);

        slidingTabLayout.setViewPager(vp,strings.toArray(new String[strings.size()]));


        slidingTabLayout.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {

            }

            @Override
            public void onTabReselect(int position) {

            }
        });

        vp.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {

                if(position == 1){
                    View decorView = getWindow().getDecorView();
                    decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN|View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
//        decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN|View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
                    getWindow().setStatusBarColor(Color.TRANSPARENT);
                }else{
                    View decorView = getWindow().getDecorView();
//                    decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN|View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN|View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
                    getWindow().setStatusBarColor(Color.BLACK);
                }


            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

////        slidingTabLayout.getCurrentTab();
//        slidingTabLayout.set
    }
}
